package com.lx.sync.core.validator;

import com.lx.sync.core.model.SyncBaseDTO;
import lombok.extern.slf4j.Slf4j;
import java.util.List;

/**
 * 抽象数据校验器
 */
@Slf4j
public abstract class AbstractDataValidator implements DataValidator {

    protected DataValidator next;

    @Override
    public void setNext(DataValidator next) {
        this.next = next;
    }

    @Override
    public DataValidator getNext() {
        return next;
    }

    @Override
    public ValidationResult validate(List<? extends SyncBaseDTO> dataList) {
        ValidationResult result = doValidate(dataList);

        if (result.isValid() && next != null) {
            ValidationResult nextResult = next.validate(dataList);
            result.merge(nextResult);
        }

        return result;
    }

    /**
     * 执行具体的校验逻辑
     * @param dataList 待校验数据
     * @return 校验结果
     */
    protected abstract ValidationResult doValidate(List<? extends SyncBaseDTO> dataList);
}
